#include <iostream>
#include <vector>
using namespace std;

vector<int> ans = vector<int>(100005, 0);
vector<pair<int, int>> temp = vector<pair<int, int>>(100005, make_pair(-1, -1));

void mergeSort(vector<pair<int, int>>& pairs, int l, int r) {
    if (l >= r) return;
    int mid = l + (r - l) / 2;
    mergeSort(pairs, l, mid);
    mergeSort(pairs, mid + 1, r);
    int i = l, j = mid + 1;
    int cnt = 0;
    int cur = l;
    while (i <= mid && j <= r) {
        if (pairs[i].first > pairs[j].first) {
            temp[cur++] = pairs[j++];
            cnt++;
        } else {
            temp[cur++] = pairs[i];
            ans[pairs[i].second] += cnt;
            i++;
        }
    }
    if (j == r + 1) {
        while (i <= mid) {
            temp[cur++] = pairs[i];
            ans[pairs[i].second] += cnt;
            i++;
        }
    } else {
        while (j <= r) { temp[cur++] = pairs[j++]; }
    }
    for (int t = l; t <= r; t++) { pairs[t] = temp[t]; }
}

vector<int> countSmaller(vector<int>& nums) {
    vector<pair<int, int>> prs(nums.size());
    for (int i = 0; i < nums.size(); i++) { prs[i] = make_pair(nums[i], i); }
    mergeSort(prs, 0, prs.size() - 1);
    return vector<int>(ans.begin(), ans.begin() + nums.size());
}